<template>
  <el-dialog :title="!bugid ? '添加Bug':'提交方案'" :visible.sync="dialogFormVisibleBUG" width="95%" :close-on-click-modal="false" style="text-align: left">
    <el-form :model="form">

      <el-form-item label="严重等级：">
        <el-select v-model="form.value" placeholder="请选择等级">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="bug内容：">
        <el-input
          type="textarea"
          :autosize="{ minRows: 2, maxRows: 4}"
          placeholder="请输入bug内容"
          v-model="form.content">
        </el-input>
      </el-form-item>

      <el-form-item label="提交方案：" v-show="solebug">
        <el-input
          type="textarea"
          :autosize="{ minRows: 2, maxRows: 4}"
          placeholder="请输入提交方案"
          v-model="form.sole">
        </el-input>
      </el-form-item>

    </el-form>
    <div style="margin-top: 20px;text-align: right">
      <button class="cancelcss" @click="dialogFormVisibleBUG = false">取 消</button>
      <button class="logincss" @click="SubmitArticles">提 交</button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: "BugModules",
  data() {
    return {
      dialogFormVisibleBUG: false,
      solebug: false,
      bugid: 0,
      form: {
        value: '',
        content: '',
        sole: ''
      },
      options: [{
        value: '高',
        label: '高'
      }, {
        value: '低',
        label: '低'
      }]
    }
  },
  methods:{
    soles(){
      if(this.bugid > 0) this.solebug = true;
      else this.solebug = false;
    },
    showoverBUG(data){
      if(data == 0){
        this.bugid = 0
        this.form.value = ""
        this.form.content = "";
        this.form.sole = "";
        this.soles()
      }
      else{
        this.bugid = data
        this.axios.post(this.Global.BASE_URL+'/BugController/updataBUGdata',
          {I:data}).then((res)=>{
          if("2000" == res.data.msg){
            this.form.value = res.data.data.buggrade
            this.form.content = res.data.data.bugcontent
            this.form.sole = res.data.data.bugsolve
            this.soles()
          }
          else this.$CustomMessage_WAENING('bug内容','回填失败！');
        }).catch(erroe=>{
          this.$CustomMessage_ERROR('bug内容','回填错误！');
        })
      }
      this.dialogFormVisibleBUG = true;
    },
    SubmitArticles(){
      let D = this.form.value.trim(),
        C = this.form.content.trim(),
        S = this.form.sole.trim(),
        I = this.bugid
      if((D == "高" || D == "低") && C.length > 0){
        this.axios.post(this.Global.BASE_URL+'/BugController/InsertBUG',
          {D:D,C:C,S:S,I:I}).then((res)=>{
          if("2000" == res.data.msg){
            this.dialogFormVisibleBUG = false
            this.$parent.ThisBugReload()
            if(I <= 0) this.$CustomMessage_OK('bug内容','添加bug完成！')
            else this.$CustomMessage_OK('bug内容','提交方案完成！')
          }
          else if("1000" == res.data.msg){
            this.$CustomMessage_WAENING('bug内容','请填写完整！');
          }
          else this.$CustomMessage_WAENING('bug内容','添加失败！');
        }).catch(erroe=>{
          this.$CustomMessage_ERROR('bug内容','内容错误！');
        })
      }else this.$CustomMessage_WAENING('bug内容','请填写完整！');
    }
  }
}
</script>

<style scoped>
.cancelcss{
  border: 1px solid #e5e9f2;
  border-radius: 7px;
  padding: 10px 15px;
  outline: none;
}
.logincss{
  border: 1px solid #e5e9f2;
  border-radius: 7px;
  padding: 10px 15px;
  background: #409EFF;
  color: white;
  outline: none;
}
</style>
